//
//  XLUserCenterDataCell.m
//  industry
//
//  Created by xl on 2020/11/24.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLUserCenterDataCell.h"
#import "XLAppletModel.h"

@interface XLUserCenterDataCell ()

@property (nonatomic, strong) XLView *cardBgView;
@property (nonatomic, strong) XLImageView *cardIG;
@property (nonatomic, strong) XLLabel *cardLB;
@property (nonatomic, strong) XLView *archiveBgView;
@property (nonatomic, strong) XLImageView *archiveIG;
@property (nonatomic, strong) XLLabel *archiveLB;

@end
@implementation XLUserCenterDataCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteBgColor];
        
        [self.contentView addSubview:self.cardBgView];
        [_cardBgView addSubview:self.cardIG];
        [_cardBgView addSubview:self.cardLB];
        [self.contentView addSubview:self.archiveBgView];
        [_archiveBgView addSubview:self.archiveIG];
        [_archiveBgView addSubview:self.archiveLB];
        
        [self makeConstrains];
    }
    return self;
}

- (void)makeConstrains {
    CGFloat width = (SCREEN_WIDTH - 30*2 - 10)/2.0;
    [_cardBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(30);
        make.top.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(width, 60));
    }];
    
    [_archiveBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-30);
        make.top.equalTo(self.cardBgView);
        make.size.mas_equalTo(CGSizeMake(width, 60));
    }];
    
    [_cardIG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cardBgView).offset(10);
        make.centerY.equalTo(self.cardBgView);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [_cardLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cardIG.mas_right).offset(15);
        make.centerY.equalTo(self.cardBgView);
    }];
    
    [_archiveIG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.archiveBgView).offset(15);
        make.centerY.equalTo(self.archiveBgView);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [_archiveLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.archiveIG.mas_right).offset(15);
        make.centerY.equalTo(self.archiveBgView);
    }];
    
}

- (void)loadCellDataCardModel:(XLAppletModel *)cardModel
                 archiveModel:(XLAppletModel *)archiveModel {
    [_cardIG sd_setImageWithURL:XLWebIMAGEURL(cardModel.appletIcon)];
    _cardLB.text = cardModel.appletName;
    [_archiveIG sd_setImageWithURL:XLWebIMAGEURL(archiveModel.appletIcon)];
    _archiveLB.text = archiveModel.appletName;
}

#pragma mark - UITapGestureRecognizer
- (void)clickCard {
    if (self.cardBlock) {
        self.cardBlock();
    }
}

- (void)clickArchive {
    if (self.archiveBlock) {
        self.archiveBlock();
    }
}

#pragma mark - setter/getter
- (XLView *)cardBgView {
    if (!_cardBgView) {
        _cardBgView = [XLView new];
        _cardBgView.backgroundColor = [UIColor grayBgColor];
        _cardBgView.layer.cornerRadius = 12.0f;
        _cardBgView.layer.masksToBounds = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCard)];
        [_cardBgView addGestureRecognizer:tap];
    }
    return _cardBgView;
}

- (XLView *)archiveBgView {
    if (!_archiveBgView) {
        _archiveBgView = [XLView new];
        _archiveBgView.backgroundColor = [UIColor grayBgColor];
        _archiveBgView.layer.cornerRadius = 12.0f;
        _archiveBgView.layer.masksToBounds = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickArchive)];
        [_archiveBgView addGestureRecognizer:tap];
    }
    return _archiveBgView;
}

- (XLImageView *)cardIG {
    if (!_cardIG) {
        _cardIG = [XLImageView new];
        _cardIG.image = XLIMAGE(@"edit");
    }
    return _cardIG;
}

- (XLImageView *)archiveIG {
    if (!_archiveIG) {
        _archiveIG = [XLImageView new];
        _archiveIG.image = XLIMAGE(@"edit");
    }
    return _archiveIG;
}

- (XLLabel *)cardLB {
    if (!_cardLB) {
        _cardLB = [XLLabel new];
        _cardLB.font = [UIFont fontOfPingFangSCRegularWithSize:14];
        _cardLB.textColor = [UIColor blackFontColor];
        _cardLB.text = @"我的名片";
    }
    return _cardLB;
}

- (XLLabel *)archiveLB {
    if (!_archiveLB) {
        _archiveLB = [XLLabel new];
        _archiveLB.font = [UIFont fontOfPingFangSCRegularWithSize:14];
        _archiveLB.textColor = [UIColor blackFontColor];
        _archiveLB.text = @"个人档案";
    }
    return _archiveLB;
}
@end
